package cn.tedu.sentinel01;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class Sentinel01Application {


    public static void main(String[] args) {

        SpringApplication.run(Sentinel01Application.class, args);

        //设置资源的规则定义
        //定义规则  一个或者是多个
        List<FlowRule> flowRules =new ArrayList<>();
        //给数组里面防止规则
        //需要创建规则对象
        FlowRule f = new FlowRule();
        //设置具体规则
        //规则对应的资源
        f.setResource("sayhi");
        //1 代表qps  一台服务器每秒能响应的查询次数
        // 0 并发  系统同时能处理的请求此时
        f.setGrade(1);
        //设置阈值
        f.setCount(1);
        //规则添加道集合里面
        flowRules.add(f);
        //启动的时候加载规则
        FlowRuleManager.loadRules(flowRules);
    }


}
